package org.lw.provider.service.impl;


import org.lw.provider.Entity.User;
import org.lw.provider.mapper.UserMapper;
import org.lw.provider.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {

    private final UserMapper userMapper;

    // 使用构造函数注入 UserMapper
    @Autowired
    public UserServiceImpl(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    // 插入用户
    public void addUser(User user) {
        userMapper.insertUser(user);
    }

    // 根据 ID 查询用户
    public User findUserById(int id) {
        return userMapper.getUserById(id);
    }

    // 查询所有用户
    public List<User> findAllUsers() {
        return userMapper.getAllUsers();
    }

    // 更新用户
    public void updateUser(User user) {
        userMapper.updateUser(user);
    }

    // 删除用户
    public void deleteUser(int id) {
        userMapper.deleteUser(id);
    }
}

